package solution._0050._0053;

/**
 * Created by chen_snow
 * Date: 2021/6/9 20:26
 * Description: 最大子序和
 */
public class Solution {
    public int maxSubArray(int[] nums) {

        int max = Integer.MIN_VALUE;
        int current = 0;

        for (int i = 0; i < nums.length; i++) {
            if (current >= 0) {
                current += nums[i];
            } else {
                current = nums[i];
            }

            max = Math.max(max, current);
        }
        return max;
    }
}
